﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;
using SchoolBusiness;

namespace SchoolAdministration
{
    public partial class Edituserdetails : System.Web.UI.Page
    {
        private readonly UserAccount _dm = new UserAccount();
        private UserData user = new UserData();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<UserData> roles = new List<UserData>();
                roles = _dm.GetUserRoles();
                DropRoleId.DataSource = roles;
                DropRoleId.DataTextField = "UserRoles";
                DropRoleId.DataValueField = "RoleId";
                DropRoleId.DataBind();

            }
            int id = Convert.ToInt32(Request.QueryString["Id"]);
            LoadEditUserInfo(id);

        }
        public void LoadEditUserInfo(int id)
        {
            TXTUserId.Text = id.ToString();
            TXTUserId.Enabled = false;
            user = _dm.GetUserById(id);
            //TxtSubject.TextChanged+=;
            // TxtSubject.Text= ;
            ////  TxtSubject.EnableViewState = false;
            //   TxtSubjectCode.Text = sub.SubjectCode;
            //  ClassDropdown.Text = sub.ClassGrade.ClassName;

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            user.UserName = TxtUserName.Text;
            user.Firtname = TxtFirstName.Text;
            user.LastName = TxtLastName.Text;
            user.Email = TxtEMail.Text;
            user.role.RoleId = Int32.Parse(DropRoleId.Text);
            user.IsActive = CkBoxUserId.Checked;
            int id = Convert.ToInt32(Request.QueryString["Id"]);
            user.id = id;
            int result = _dm.UpdateUserById(user);
            if (result > 0)
            {
                Helper.Alert.Show("Successfully Edited subject");

            }



        }
    }
}